import {SysNewsCategoryData, SysNewsCategoryAdd} from "@/pages/news/category/type";
import {ReactNode} from "react";
import {UseFetchDataAction} from "@ant-design/pro-table/es/typing";
import {Button, Space} from "antd";
import {ProColumns} from "@ant-design/pro-table";
import {OptionActions} from "@/type/type";
import AddSysNewsCategory from "@/pages/news/category/list/components/AddSysNewsCategory";
import AuthWrapper from "@/components/AuthWrapper";

// @ts-ignore
const columns: ProColumns<SysNewsCategoryData> = (optionAction: OptionActions<SysNewsCategoryAdd, SysNewsCategoryData>) => {
  return [
    {
      dataIndex: "index",
      valueType: "index",
      title: "序号" ,
    },
    {
      title: "分类名称",
      dataIndex: "name",
      align: 'center',
    },
    {
      title: "操作",
      valueType: 'option',
      align: "center",
      key: "option",
      width: "200px",
      render: (text: ReactNode, record: SysNewsCategoryData, index: number, action: UseFetchDataAction<SysNewsCategoryData>) => {
        return (
          <Space>
            <AuthWrapper authorize={""}>
              {(authorized: boolean) => <AddSysNewsCategory initialValues={record}
                                                            disabled={!authorized} {...optionAction.editModal(record, authorized)}/>}
            </AuthWrapper>
            <AuthWrapper authorize={""}>
              {(authorized: boolean) => <Button type="link" disabled={!authorized} danger onClick={() =>
                optionAction.remove([record.id])}>删除</Button>}
            </AuthWrapper>
          </Space>
        )
      }
    }
  ]


}


export default columns;
